import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {MatrixStateGroupTotal} from '../matrix-state-group-total';
import {MatrixStateTotal} from '../matrix-state-total';


@Component({
  selector: 'app-matrix-total',
  templateUrl: './matrix-total.component.html',
  styleUrls: ['./matrix-total.component.css']
})
export class MatrixTotalComponent implements OnInit {


  @Input()
  totalName: string;

  @Input()
  matrixStateGroupTotals: MatrixStateGroupTotal[];

  /**
   * 选中项发生改变
   *
   *
   * @memberof FarmSelectorComponent
   */
  @Output() public selectedChange: EventEmitter<MatrixStateGroupTotal[]> = new EventEmitter<MatrixStateGroupTotal[]>();

  constructor() {
  }

  ngOnInit() {

  }

  onClick(event: HTMLInputElement, currMatrixStateTotal: MatrixStateTotal) {
    currMatrixStateTotal.isChecked = event.checked;
    this.selectedChange.emit(this.matrixStateGroupTotals);
  }

  onGroupClick(event: HTMLInputElement, currMatrixStateGroupTotal: MatrixStateGroupTotal) {
    if (event.checked) {
      currMatrixStateGroupTotal.stateTotals.map(o => o.isChecked = true)
    }
    else {
      currMatrixStateGroupTotal.stateTotals.map(o => o.isChecked = false)
    }
    this.selectedChange.emit(this.matrixStateGroupTotals);
  }
}
